<template>
  <div class="my">
    <header>
      <img src="https://api-haoke-web.itheima.net/img/profile/bg.png" alt />
      <div class="info">
        <img src="https://api-haoke-web.itheima.net/img/profile/avatar.png" alt />
        <div>
          <p>{{token?'昵称':'游客'}}</p>
          <button v-show="token" @click="back" class="back">退出</button>
          <button v-show="!token" @click="goLogin" class="goLogin">去登陆</button>
          <p v-show="token">
            <span>编辑个人资料</span>
            <van-icon name="play" />
          </p>
        </div>
      </div>
    </header>
    <main>
      <van-grid :column-num="3" :border="false" icon-size="22" gutter="20" :clickable="true">
        <van-grid-item icon="wap-home-o" text="我的出租" />
        <van-grid-item icon="underway-o" text="看房记录" />
        <van-grid-item icon="send-gift-o" text="成为房主" to="/rent" />
        <van-grid-item icon="friends-o" text="个人资料" />
        <van-grid-item icon="service-o" text="联系我们" />
      </van-grid>
      <div class="img">
        <img src="https://api-haoke-web.itheima.net/img/profile/join.png" alt="">
      </div>
    </main>
  </div>
</template>

<script>
export default {
  data() {
    return {
      token: ""
    };
  },
  methods: {
    back() {
      this.token = sessionStorage.removeItem("token");
    },
    goLogin() {
      this.$router.push("/login");
    }
  },
  created() {
    this.token = window.sessionStorage.getItem("token");
  }
};
</script>

<style scoped lang="less">
.my {
  width: 100%;
  height: 100%;
  header {
    position: relative;
    width: 100%;
    height: 300px;
    img {
      width: 100%;
    }
    .info {
      position: absolute;
      background: #fff;
      width: 85%;
      height: 55%;
      bottom: 0;
      left: 50%;
      -webkit-transform: translateX(-50%);
      transform: translateX(-50%);
      box-shadow: 0 0 10px 3px #ddd;
      margin: 50px auto 0;
      padding: 0 20px;
      text-align: center;
      font-size: 13px;
      img {
        width: 80px;
        height: 80px;
        border-radius: 50%;
        border: 5px solid #fff;
        position: relative;
        top: -50px;
      }
      div {
        margin-top: -40px;
        .back {
          margin: 8px 0 13px 0;
          border-radius: 30px;
          color: #fff;
          padding: 2px 15px;
          background: #21b97a;
          font-size: 12px;
          border: none;
        }
        .goLogin {
          color: #fff;
          padding: 8px 15px;
          background: #21b97a;
          font-size: 12px;
          border: none;
          border-radius: 4px;
          margin-top: 20px;
        }
        :nth-child(4) {
          color: rgb(153, 152, 152);
        }
      }
    }
  }
}
main {
  width: 100%;
  .van-grid{
    padding: 20px 0;
  }
}
.img{
  width: 100%;
  padding:0 15px;
  img{
    width: 100%;
  }
}
</style>
